package processor;

import java.io.File;
import java.net.Socket;
import java.net.URL;
import java.net.URLClassLoader;
import javax.servlet.http.HttpServlet;
import constants.Constants;
import request.*;
import response.*;

public class DefaultServletProcessor implements Processor{

	@Override
	public void process(HttpRequest request, HttpResponse response) {
		String uri=request.getUri();
		String servletName=uri.substring(uri.lastIndexOf("/")+1);
		
		try{
		URL[] url=new URL[1];
		File servletClassPath=new File(Constants.getWebRoot());
		url[0]=new URL(servletClassPath.getPath());
		URLClassLoader urlClassLoader=new URLClassLoader(url);
		Class servletClass=urlClassLoader.loadClass(servletName);
		HttpServlet instanceHttpServlet=(HttpServlet)servletClass.newInstance();
		instanceHttpServlet.service(request, response);
		}
		catch(Exception e){
			
		}
	}

	
	
}
